<template>
    <base-breadcrumb>
        <searchData :search-data="searchArr" @search="search"/>

        <a-card>
          <list-table
            ref="table"
            class="export-table"
            :columns="columns"
            :request="loadData"
            :isShowTotal="false"
            :pageKeys="['pageNum', 'pageSize', 'total']"
            :statisticsConfig="{use: true, temp: statisticsTemp}"
            :exportConfig="{ use: true,select: '总包结算定案',all: '总包结算定案'}"
            :exportPermission="{ select: 'bm_033_exp_03', all: 'bm_033_exp_03' }"
          >

<!--            <template slot="prefix" slot-scope="ref">-->
<!--              <a-button @click="handleDetial('add')" type="primary" v-btnPermission="'bm_033_add_01'">新增</a-button>-->
<!--            </template>-->

            <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
            <span slot="createTime" slot-scope="text, record, index">
              {{ text ? text.split(' ')[0] : text }}
            </span>

<!--            <template slot="auditStatus" slot-scope="text, record, index">-->
<!--              &lt;!&ndash; （0：草稿，未提交/1：已提交，审核中/2:资料上传中/3:审批通过/4：已作废/5：审批不通过 &ndash;&gt;-->
<!--              <list-status-->
<!--                :color="['yellow', 'blue', 'grey', 'green', 'grey', 'red'][text]"-->
<!--                :text="['未提交', '审核中', '', '审批通过', '已作废', '审批不通过'][text]"-->
<!--              />-->
<!--            </template>-->

            <!-- 操作 -->
            <template slot="operation" slot-scope="text, record">
              <MoreButton>
              <a @click="handleDetial('view', record)" v-btnPermission="'bm_033_loo_02'">查看</a>
              <span v-btnPermission="'bm_033_edi_01'" v-if="record.auditStatus == 0 || record.auditStatus == 5">
                <a @click="handleDetial('edit', record)">编辑</a>
              </span>
<!--              <span v-btnPermission="'bm_033_del_03'" v-if="record.auditStatus == 0 || record.auditStatus == 5">-->
<!--                <a @click="handleAction('del', '删除', record)">删除</a>-->
<!--              </span>-->
<!--              <span v-btnPermission="'bm_033_tov_05'" v-if="record.auditStatus == 3">-->
<!--                <a @click="handleAction('revoke', '作废', record)">作废</a>-->
<!--              </span>-->
<!--              <span v-if="record.auditStatus == 1 && record.modifiedId == currentUser&&hideBuquBtn()">-->
<!--                <a @click="handleAction('cancel', '撤销', record)">撤销</a>-->
<!--              </span>-->
              <span v-if="record.auditStatus != 0" v-btnPermission="'bm_033_loo_02'">
                <approval-button :id="record.id" text="审批信息"></approval-button>
              </span>
              </MoreButton>
            </template>
          </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { getFinalList, getTopTotal, finalApprovalDelete, finalApprovalCancel, finalApprovalRevoke } from '@/api/businessAffairs/finalApproval'
const columns = [
    {
        title: '序号',
        width: '65px',
        scopedSlots: { customRender: 'serial' },
    },
    {
        title: '所属分公司',
        width: 120,
        dataIndex: 'branchComName',
    },
    {
        title: '所属项目',
        width: 200,
        dataIndex: 'projectName',
    },
    {
        title: '名称',
        width: 200,
        dataIndex: 'name',
    },
    {
        title: '结算报审值（含税）（万元）',
        width: 160,
        dataIndex: 'reportAfterValue',
    },
    {
        title: '审定金额（含税）（万元）',
        width: 160,
        dataIndex: 'authorizedAmountHas',
    },
    {
        title: '实际成本（含税）（万元）',
        width: 160,
        dataIndex: 'actualCostHas',
    },
    {
        title: '利润额（万元）',
        width: 130,
        dataIndex: 'amountProfit',
    },
    {
        title: '利润率%',
        width: 120,
        dataIndex: 'profitRate',
    },
    {
        title: '填报人',
        width: 200,
        dataIndex: 'creatorName',
    },
    {
        title: '填报时间',
        width: 200,
        dataIndex: 'createTime',
        scopedSlots: { customRender: 'createTime' },
    },
    {
      title: '审定结算书日期',
      width: 200,
      dataIndex: 'judgementSettlementTime',
    },
    {
        title: '状态',
        width: 200,
        dataIndex: 'auditStatusName'
    },
    {
        title: '操作',
        dataIndex: 'operation',
        fixed: 'right',
        width: '230px',
        scopedSlots: { customRender: 'operation' },
    },
]
export default {
    name:'a'+Date.now(),
    data() {
        this.columns = columns
        return {
            loadData: (parameter) => {
              let that = this
              let param = { ...this.queryParam }
              // startTime', 'endTime'
              if (param.startTime) param.startTime = param.startTime + ' 00:00:00'
              if (param.endTime) param.endTime = param.endTime + ' 23:59:59'
              const requestParameters = Object.assign({}, parameter, { param: param })
              getTopTotal(param)
              .then((res) => {
                  this.loading.isTable = false
                  this.from = res.data
              })
              .catch(() => {
                  this.loading.isTable = false
              })
              return getFinalList(requestParameters).then((res) => {
                if (res.code == 0) {
                  res.data.list.forEach(item=>{
                    item.auditStatusName = ['待提交审批', '审核中', '', '审批通过', '已作废', '审批不通过'][item.auditStatus]
                  })
                  return { code: 200, ...res.data, data: res.data.list }
                }
                return { code: 200, data: [] }
              })
            },
            loading: {
                isTable: false,
            },
            queryParam: {},
            from: {
              reportAfterValue: '0',
              authorizedAmountHas: '0',
              actualCostHas: '0',
              amountProfit: '0',
              profitRate: '0'
            },
            statisticsTemp: () => {
              // 结算报审值（含税）（万元）:1000.00   |
              // 审定金额（含税）（万元）: 8 000.00  |
              // 实际成本（含税）（万元）：1 000  |   利润额（含税）（万元）：1000.00 |  利润率%: 8 000.00
                return (
                    <span>
                      <span>结算报审值（含税）（万元）：<a> { this.from.reportAfterValue } </a></span>
                      <span><span style="margin: 0 5px">|</span>审定金额（含税）（万元）：<a> { this.from.authorizedAmountHas }</a></span>
                      <span><span style="margin: 0 5px">|</span>实际成本（含税）（万元：<a> { this.from.actualCostHas } </a></span>
                      <span><span style="margin: 0 5px">|</span>利润额（含税）（万元）：<a> { this.from.amountProfit } </a></span>
                      <span><span style="margin: 0 5px">|</span>利润率%：<a> { this.from.profitRate } </a></span>
                      <span></span>
                    </span>
                )
            },
        }
    },
    computed: {
      currentUser() {
        return this.$userInfo().userId
      },
      searchArr() {
        return [
          // 搜索框
          {
            name: '所属单位',
            valueKey: 'searchQuery',
            type: OrgTreeSelect,
          },
          // {
          //   name: '分公司',
          //   valueKey: 'branchComId',
          //   type: SelectSubCompany
          // },
          // {
          //   name: '项目',
          //   keyValue: 'branchComId',
          //   valueKey: 'projectId',
          //   type: SelectProject
          // },
          {
              name: '名称',
              type: 'input',
              value: 'name'
          },
          {
              name: '填报人',
              type: 'input',
              value: 'creatorName'
          },
          {
              name: '填报时间',
              type: 'dateRange',
              value: 'activityDate',
              attr: {
                  rangeFormat: ['startTime', 'endTime']
              }
          },
          {
            name: '审定结算书日期',
            type: 'dateRange',
            value: 'judgementSettlementTime',
            attr: {
              rangeFormat: ['judgementSettlementTimeBegin', 'judgementSettlementTimeEnd']
            }
          },
          {
            name: '状态',
            value: 'auditStatus',
            placeholder: '关键字',
            type: 'select',
            //（0：草稿，未提交/1：已提交，审核中/2:资料上传中/3:审批通过/4：已作废/5：审批不通过
            data: [
              {
                label: '待提交审批',
                value: '0'
              },
              {
                label: '审核中',
                value: '1'
              },
              {
                label: '审批通过',
                value: '3'
              },
              // {
              //   label: '已作废',
              //   value: '4'
              // },
              {
                label: '审批不通过',
                value: '5'
              }
            ]
          }
        ]
      }
    },
    created() {
    },
    methods: {
        search(values) {
          this.queryParam = { ...values }
          this.$refs.table.refresh()
        },
        handleAction(type, action, e) {
          let apiMap = {
            del: finalApprovalDelete,
            revoke: finalApprovalRevoke,
            cancel: finalApprovalCancel
          }
          let api = apiMap[type]
          let that = this
          that.$confirm({
              title: '温馨提示',
              content: `确定是否${action}？`,
              okText: '确认',
              okType: 'danger',
              cancelText: '取消',
              onOk() {
                return api( e.id)
                  .then((res) => {
                      that.$message.success(`${action}成功！`)
                      that.$refs.table.refresh()
                  })
                  .catch((res) => {
                      that.$message.warning(`${action}失败！`)
                  })
              },
          })
        },
        handleDetial(type, record) {
          let query = { type }
          if (type !== 'add') {
            query.id = record.id
          }
          this.$router.push({
              path: '/businessAffairs/totalSettlement/finalApproval/edit',
              query,
          })
        },
    },
}
</script>

<style lang="less">
.not-submit {
    display: inline-block;
    padding: 0;
    li {
        list-style: none;
        color: red;
    }
}
.submitted {
    display: inline-block;
    padding: 0;
    li {
        list-style: none;
        color: green;
    }
}
</style>
